<?php
/**
 *环球职业教育在线API类
 *@author sulwan@126.com
 *@date 2009-11-20
 各功能下必须要传送的参数进行规定如下：
        1、获取课程类别：Md5Str、SID、Cataid、Time、Key
        2、获取班别：Md5Str、SID、Cataid、lesson_type_code、Time、Key
        3、获取讲：Md5Str、SID、Cataid、class_code、Time、Key
        4、获取套餐：Md5Str、SID、Cataid、lesson_type_code、Time、Key

 */

class edu24 extends Application{

	public function __construct() {
		parent::__construct();
	}
//获取课程类别：Md5Str、SID、Cataid、Time、Key
public static function getCourseClass() {
	global $sid,$key,$urlCoure;
	$data = getCache(EDU24,'coureClass',1);
	if(empty($data)) {
		$tm = date('YmdHis');
		$Cataid = 1;
		$Md5Str = md5($sid.$Cataid.$lesson_type_code.$lesson_code.$class_code.$tm.$key);
		$enStr = urlencode($Md5Str.'$'.$sid.'$'.$Cataid.'$'.$lesson_type_code.'$'.$lesson_code.'$'.$class_code.'$'.$tm);
		$strUrl = $urlCoure.'?en='.$enStr;
		print_r($strUrl);exit;
		$coureClass = file_get_contents($strUrl);
		$data = getXmlData($coureClass);
		setCache(EDU24,'coureClass',$data,1);
	}
	
	$sql = "TRUNCATE `core_up_type`";
	$this->_db->execute($sql);
	$sql = "TRUNCATE `core_lesson_type`";
	$this->_db->execute($sql);
	$sql = "TRUNCATE `core_lesson`";
	$this->_db->execute($sql);
	foreach($data as $key=>$value){
		if(is_array($value)){
			foreach($value as $ke=>$va){
				$up_type_code = $va['up_type_code'];
				$up_type_name = $va['up_type_name'];
				$up_class_num = $va['class_num'];
				if(!empty($up_class_num) && abslength($up_type_name) >= 2){
					$sql = "replace INTO `core_up_type` (`up_type_code`, `up_type_name`, `class_num`) VALUES ('".$up_type_code."', '".$up_type_name."', '".$up_class_num."');";
					$this->_db->execute($sql);
				}
				if(is_array($va['lesson_type'])){
					foreach($va['lesson_type'] as $k=>$v){
						$lesson_type_code = $v['lesson_type_code'];
						$lesson_type_class_num = $v['class_num'];
						$lesson_type_name = $v['lesson_type_name'];
						if(!empty($lesson_type_class_num)&& abslength($lesson_type_name) >= 2){
							$sql = "replace INTO `core_lesson_type` (`up_type_code`, `lesson_type_code`, `lesson_type_name`, `lesson_class_num`) VALUES ('".$up_type_code."', '".$lesson_type_code."','".$lesson_type_name."','".$lesson_type_class_num."');";
							$this->_db->execute($sql);
						}
						if(is_array($v['lesson'])){
							foreach($v['lesson'] as $j=>$w){
								$lesson_code = $w['lesson_code'];
								$lesson_name = $w['lesson_name'];
								$lesson_class_num = $w['class_num'];
								if(!empty($lesson_class_num)&& abslength($lesson_name) >= 2){
									$sql = "replace INTO `core_lesson` (`lesson_type_code`, `lesson_code`, `lesson_name`, `lesson_class_num`, `tmid`) VALUES ('".$lesson_type_code."','".$lesson_code."', '".$lesson_name."','".$lesson_class_num."','".md5($lesson_type_code.$lesson_code.$lesson_name.$lesson_class_num)."');";
									$this->_db->execute($sql);
								}
							}
						}
					}
				}
			}
		}
	}
}

//core_up_type
//获取班别：Md5Str、SID、Cataid、lesson_type_code、Time、Key
public static function getGad($lesson_type_code){
	global $sid,$key,$urlCoure;
	$data = getCache(EDU24,'getGad'.'-'.$lesson_type_code,1);
	if(empty($data)) {
		$tm = date('YmdHis');
		$Cataid = 2;
		$Md5Str = md5($sid.$Cataid.$lesson_type_code.$lesson_code.$class_code.$tm.$key);
		$enStr = urlencode($Md5Str.'$'.$sid.'$'.$Cataid.'$'.$lesson_type_code.'$'.$lesson_code.'$'.$class_code.'$'.$tm);
		$strUrl = $urlCoure.'?en='.$enStr;
		$coureClass = file_get_contents($strUrl);
		//$coureClass = encodeconvert('gb2312',$coureClass);
		$datase = getXmlData($coureClass);
		setCache(EDU24,'getGad'.'-'.$lesson_type_code,$datase,1);
	}
	return $data;
}

//core_lesson_type
//获取讲：Md5Str、SID、Cataid、class_code、Time、Key
public static function getJ($class_code){
	global $sid,$key,$urlCoure;
	$data = getCache(EDU24,'getJ'.'-'.$class_code,1);
	if(empty($data)) {
		$tm = date('YmdHis');
		$Cataid = 3;
		$Md5Str = md5($sid.$Cataid.$lesson_type_code.$lesson_code.$class_code.$tm.$key);
		$enStr = urlencode($Md5Str.'$'.$sid.'$'.$Cataid.'$'.$lesson_type_code.'$'.$lesson_code.'$'.$class_code.'$'.$tm);
		$strUrl = $urlCoure.'?en='.$enStr;
		//print_r($strUrl);exit;
		$coureClass = file_get_contents($strUrl);
		$data = getXmlData($coureClass);
		setCache(EDU24,'getJ'.'-'.$class_code,$data,1);
	}
	return $data;
}
//
////core_lesson_type
////获取套餐：Md5Str、SID、Cataid、lesson_type_code、Time、Key
//public static function getC($lesson_type_code){
//	global $sid,$key,$urlCoure;
//	//$data = getCache(EDU24,'getGad'.'-'.$lesson_type_code,1);
//	if(empty($data)) {
//		$tm = date('YmdHis');
//		$Cataid = 4;
//		$Md5Str = md5($sid.$Cataid.$lesson_type_code.$lesson_code.$class_code.$tm.$key);
//		$enStr = urlencode($Md5Str.'$'.$sid.'$'.$Cataid.'$'.$lesson_type_code.'$'.$lesson_code.'$'.$class_code.'$'.$tm);
//		$strUrl = $urlCoure.'?en='.$enStr;
//			print_r($strUrl);exit;
//		$coureClass = file_get_contents($strUrl);
//		$data = getXmlData($coureClass);
//		setCache(EDU24,'getGad'.'-'.$lesson_type_code,$data,1);
//	}
//}




public function getRowUp($id){
		$sql = 'SELECT * FROM `#happy_up_type` WHERE `up_type_code` = '.intval($id);
		return $this->_db->getRow($sql);
}

public function getAllType($id){
	$sql = 'SELECT * FROM `core_lesson_type` WHERE `up_type_code`  = '.intval($id);
	return $this->_db->getAll($sql);
}

public function getRowType($id){
	$sql = 'SELECT * FROM `core_lesson_type` WHERE `lesson_type_code`  = '.intval($id);
	return $this->_db->getRow($sql);
}
}?>